<template>
	<view class="card refund-rule" v-if="hasRefundRule">
		<view class="card-title">取消说明</view>
		<view
			class="tourist-refund"
			:class="{ 'tourist-refund-box': ta_refund_fee_rules?.length }"
			v-if="tourist_refund_fee_rules?.length"
		>
			<view class="refund-type">用户取消</view>
			<view class="table">
				<view class="table-header">
					<view class="first-td">取消时间</view>
					<view class="second-td">损失费用</view>
				</view>
				<view class="table-tr" v-for="(item, index) in tourist_refund_fee_rules" :key="index">
					<view class="first-td">{{ item.rule_content }}</view>
					<view class="second-td">{{ format(item.ten_thousandth) }}</view>
				</view>
			</view>
			<view class="tip-text">如使用优惠，则损失费用按照优惠前金额的比例收取，最高不超过实付金额。</view>
			<view class="tip-text">*产品不支持部分退</view>
		</view>
		<view class="ta-refund" v-if="ta_refund_fee_rules?.length">
			<view class="refund-type">商家取消</view>
			<view class="tip-text no-margin">*损失费用按照优惠前金额收取，最高不超过实付金额。</view>
			<view class="tip-text">订单确认后商家取消，除退还全额费用外，还需按以下标准赔付违约金(不可抗因素除外)</view>
			<view class="tip-text" v-if="ta_display_penalty">{{ ta_penalty_txt }}</view>
			<view class="table">
				<view class="table-header">
					<view class="first-td">取消时间</view>
					<view class="second-td">损失费用</view>
				</view>
				<view class="table-tr" v-for="(item, index) in tourist_refund_fee_rules" :key="index">
					<view class="first-td">{{ item.rule_content }}</view>
					<view class="second-td">{{ format(item.ten_thousandth) }}</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script setup lang="ts">
import { computed } from "vue"

interface Rule {
	rule_content: string
	ten_thousandth: number
}
interface RefundRuleProps {
	// 游客退款规则
	tourist_refund_fee_rules: Rule[]
	// 旅行社违约金规则
	ta_refund_fee_rules: Rule[]
	// 是否展示旅行社赔付
	ta_display_penalty: boolean
	// 旅行社赔付文案
	ta_penalty_txt: string
}

const props = defineProps<RefundRuleProps>()

const hasRefundRule = computed(() => props?.tourist_refund_fee_rules?.length || props?.ta_refund_fee_rules?.length)

const format = (num: number) => {
	if (!num) return 0

	return `${num / 100}%`
}
</script>

<style lang="scss" scoped>
@import "../../ticket/index.scss";

.refund-rule {
	.card-title {
		margin-bottom: 32rpx;
	}

	.refund-type {
		position: relative;
		padding-left: 18rpx;
		font-weight: 500;
		font-size: 28rpx;
		color: #1d2129;
		line-height: 40rpx;

		&::before {
			content: "";
			position: absolute;
			left: 0;
			top: 50%;
			transform: translateY(-50%);
			width: 6rpx;
			height: 24rpx;
			background: #fee038;
			border-radius: 4rpx;
		}
	}

	.tip-text {
		font-size: 28rpx;
		color: #4e5969;
		line-height: 40rpx;
	}

	.table {
		overflow: hidden;
		margin-top: 24rpx;
		border-radius: 16rpx;
		border: 1rpx solid #e9eaee;

		.table-header {
			display: flex;
			align-items: center;
			background-color: #f8f8f9;
			font-size: 24rpx;
			color: #86909c !important;
			line-height: 34rpx !important;
		}

		.table-tr {
			display: flex;
			align-items: center;
			border-top: 1rpx solid #e9eaee;
			color: #1d2129;
			line-height: 36rpx;
		}
	}

	.tourist-refund {
		&.tourist-refund-box {
			padding-bottom: 40rpx;
			margin-bottom: 40rpx;
			border-bottom: 1rpx solid #e5e6eb;
		}

		.first-td {
			width: 554rpx;
			padding: 22rpx 28rpx;
			border-right: 1rpx solid #e9eaee;
		}

		.second-td {
			// padding: 22rpx 26rpx;
			flex: 1;
			text-align: center;
		}

		.tip-text {
			margin-top: 32rpx;
		}
	}

	.ta-refund {
		.refund-type {
			margin-bottom: 16rpx;
		}

		.tip-text {
			margin-top: 32rpx;

			&.no-margin {
				margin-top: 0;
			}
		}

		.first-td {
			width: 402rpx;
			padding: 22rpx 28rpx;
			border-right: 1rpx solid #e9eaee;
		}

		.second-td {
			flex: 1;
			padding: 22rpx 26rpx;
			text-align: center;
		}
	}
}
</style>
